package com.animationsp.acs.interceptor;

//import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import net.hongliang.util.FieldUtil;

import com.animationsp.acs.util.Constant;
import com.animationsp.acs.util.CookieManager;
import com.animationsp.acs.util.UserRoleUtil;
import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.Action;
//import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;
//import com.sun.corba.se.spi.orbutil.proxy.InvocationHandlerFactory;
//import com.sun.xml.internal.bind.CycleRecoverable.Context;


public class CheckLogin implements Interceptor {

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation invocation) throws Exception {

			HttpServletRequest request=ServletActionContext.getRequest();
			Cookie userCookie = CookieManager.getCookie(request, Constant.COOKIE_NAME);
			String username = "";
			if(userCookie!=null){
				String cookieValue = userCookie.getValue();
				username = cookieValue.split("/")[0];
			}else{
				username="";
			}

			if (FieldUtil.isEmpty(username)) {
				return Action.LOGIN;
			}
			
			/* 板块权限判断
			Object obj = invocation.getInvocationContext().getParameters().get("cid");
			String cidstr = null;
			if (obj instanceof String[]) {
				cidstr = ((String[]) obj)[0];
			} else if (obj instanceof String) {
				cidstr = (String) obj;
			}

			if (FieldUtil.isDigit(cidstr)
					&& UserRoleUtil.hasPerm(username, Integer.valueOf(cidstr)
							.intValue()) == false) {
				return Action.NONE;
			}
			*/
			
			return invocation.invoke();
		}

	}

